package com.example.consumer

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.client.discovery.EnableDiscoveryClient
import org.springframework.cloud.openfeign.EnableFeignClients
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.beans.factory.annotation.Autowired

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
class ConsumerServiceApplication

fun main(args: Array<String>) {
    runApplication<ConsumerServiceApplication>(*args)
}

@org.springframework.cloud.openfeign.FeignClient(name = "provider-service")
interface ProviderClient {
    @GetMapping("/hello")
    fun getHello(): String
}

@RestController
class ConsumerController(
    @Autowired private val providerClient: ProviderClient
) {
    @GetMapping("/call-provider")
    fun callProvider(): String = providerClient.getHello()
}
